#!/bin/bash

echo "hello world"

podspec_fileName=$(find *.podspec)

echo "podspec_fileName = "$podspec_fileName

last_version=$(cat $podspec_fileName | grep -E -o "([0-9]{1,3}[\.]){2}[0-9]{1,3}")

echo "last_version = "$last_version

v1=`echo $last_version | cut -d \. -f 1`
v2=`echo $last_version | cut -d \. -f 2`
v3=`echo $last_version | cut -d \. -f 3`
echo "v1 = "$v1
echo "v2 = "$v2
echo "v3 = "$v3

if [ $v3 -lt 9 ]; then
    v3=$[v3+1]
else
    v3=0
    if [ $v2 -lt 9 ]; then
        v2=$[v2+1]
    else
        v2=0
        v1=$[v1+1]
    fi
fi

echo "v1 = "$v1
echo "v2 = "$v2
echo "v3 = "$v3

new_version=$v1"."$v2"."$v3
echo "new_version = "$new_version

sed -i "_bak" "s/$last_version/$new_version/g" "$podspec_fileName"


git stauts
git add .
git commit -m '更新版本到'.$new_version
git push origin master

git tag "$new_version"
git push --tags

pod lib lint "$podspec_fileName" --allow-warnings

pod repo push WYWSpecs "$podspec_fileName" --allow-warnings
